<template>
	<article class="page page-search-helper">
		<h4 class="text-center">资源搜索助手</h4>
		<form class="page-body" @submit.prevent="searchHandler">
			<div class="row">
				<div class="col-3 left">
					<fieldset>
						<legend>网站列表</legend>
						<div class="fieldset-content">
							<div class="form-group">
								<div class="input-group">
									<input class="form-control" type="text" v-model.trim="keyword" placeholder="请输入搜索内容" />
									<span class="input-group-text" @click="searchHandler"><i
											class="fa fa-search"></i></span>
								</div>
							</div>
							<div class="form-group website-list">
								<div v-for="(v, i) in websiteList" :key="i"
									:class="['website-item', { active: i === websiteActiveIndex }]" @click="itemClick(v, i)">
									<i :class="v.icon"></i>
									{{ v.label }}
									<span class="badge bg-secondary">{{ v.tag }}</span>
								</div>
							</div>
						</div>
					</fieldset>
				</div>
				<div class="col-9 right">
					<fieldset>
						<legend>网页浏览</legend>
						<div class="fieldset-content">
							<iframe :src="iframeUrl"
								sandbox="allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox"
								referrerpolicy="no-referrer" @load="loadingCount = 0"></iframe>
							<div v-show="iframeUrl" class="iframe-btn badge rounded-pill bg-danger" @click="openByBrowser">
								在浏览器中打开</div>
							<x-loading size="large" fix v-if="loadingCount > 0"></x-loading>
						</div>
					</fieldset>
				</div>
			</div>
		</form>
	</article>
</template>

<script>
const { shell } = global.require('electron')
/* 参考的综合类网站
	巴士资源 https://bashi5.com/
	磁力大全 https://7228.org/cldq.html
	懒盘搜索 https://lzpan.com/
*/
export default {
	name: 'search-helper',
	data() {
		return {
			websiteList: [
				// 网盘类
				// {icon: 'fa fa-file-o', label: '资源精灵', tag: '百度网盘', url: 'https://www.jinglingyunpan.com/resource/search/${keyword}?searchtype=1&searchway=1'},
				{ icon: 'fa fa-file-o', label: 'V盘搜', tag: '百度网盘', url: 'http://www.vpansou.com/query?wd=${keyword}' },
				// {icon: 'fa fa-file-o', label: '盘搜搜', tag: '百度网盘', url: 'https://pansoso.com/zh/${keyword}'},
				{ icon: 'fa fa-file-o', label: '橘子盘搜', tag: '网盘', url: 'https://www.nmme.cc/s/1/${keyword}' },
				{ icon: 'fa fa-file-o', label: '学霸盘', tag: '课程', url: 'https://www.xuebapan.com/s/${keyword}-1.html' },
				{ icon: 'fa fa-file-o', label: '云盘资源分享社区', tag: '阿里云盘', url: 'https://yunpan1.com/?q=${keyword}' },
				// {icon: 'fa fa-file-o', label: '奈斯搜索', tag: '阿里云盘', url: 'https://www.niceso.fun/search/?q=${keyword}'},
				// {icon: 'fa fa-file-o', label: '凌风云', tag: '网盘', url: 'https://www.lingfengyun.com/Search/Search?wd=${keyword}&so_token=433bb1aea8c47ee97fcc858c6c24f6a6'},
				// {icon: 'fa fa-file-o', label: '优聚搜', tag: '网盘', url: 'https://ujuso.com/#/main?kw=${keyword}&type=ALL&time=ALL&exact=FALSE'},
				{ icon: 'fa fa-file-o', label: '56网盘搜索', tag: '网盘', url: 'https://www.56wangpan.com/search/kw${keyword}' },
				// {icon: 'fa fa-file-o', label: '小白盘', tag: '网盘', url: 'https://www.xiaobaipan.com/list-${keyword}.html?from=1'},
				{ icon: 'fa fa-file-o', label: '坑搜网', tag: '网盘', url: 'http://www.kengso123.com/s?st=0&wd=${keyword}' },
				// {icon: 'fa fa-file-o', label: '猪猪盘', tag: '百度网盘', url: 'http://www.zhuzhupan.com/search?query=${keyword}&s=1'},
				{ icon: 'fa fa-file-o', label: '网盘搜索-云搜索', tag: '网盘', url: 'http://www.lqkweb.com/list?q=${keyword}' },
				{ icon: 'fa fa-file-o', label: '来搜一下', tag: '网盘', url: 'https://www.laisoyixia.com/s/search?q=${keyword}&currentPage=1' },
				// {icon: 'fa fa-file-o', label: '微贴网', tag: '网盘', url: 'https://www.weitiewang.com/www/Search?wd=${keyword}&so_token=810393718be90ca1780349ee34dfa291'},
				{ icon: 'fa fa-file-o', label: '天天网盘搜索', tag: '网盘', url: 'https://www.daysou.com/s?q=${keyword}&lvs=20097&start=0&isget=1&tp=baipan&cl=0&line=3' },
				{ icon: 'fa fa-file-o', label: '猫狸盘搜', tag: '网盘', url: 'https://www.alipansou.com/search?k=${keyword}' },
				{ icon: 'fa fa-file-o', label: '熊猫搜盘', tag: '网盘', url: 'https://www.sopandas.com/e/${keyword}' },
				{ icon: 'fa fa-file-o', label: '小猪快盘', tag: '网盘', url: 'https://www.xiaozhukuaipan.com/s/search?q=${keyword}&currentPage=1' },
				{ icon: 'fa fa-file-o', label: 'fastsoso', tag: '网盘', url: 'https://www.fastsoso.cn/search?k=${keyword}' },
				// {icon: 'fa fa-file-o', label: '毕方铺', tag: '网盘', url: 'https://www.iizhi.cn/resource/search/${keyword}?searchtype=1&searchway=1'},
				{ icon: 'fa fa-file-o', label: 'BDY搜', tag: '网盘', url: 'http://www.bdyso.com/' },
				{ icon: 'fa fa-file-o', label: '网盘小站', tag: '网盘', url: 'https://wpxz.org/' },
				{ icon: 'fa fa-file-o', label: '学搜搜', tag: '影视|文献', url: 'https://www.xuesousou.com/search?q=${keyword}' },
				{ icon: 'fa fa-file-o', label: '乌鸦搜', tag: '综合', url: 'https://www.wuyasou.com/search?keyword=${keyword}' },
				// {icon: 'fa fa-file-o', label: '磁力猫', tag: '综合', url: 'http://clm7.net/search?word=${keyword}'},
				// {icon: 'fa fa-file-o', label: '磁力狗', tag: '综合', url: 'http://clg00.org/search?word=${keyword}'},
				{ icon: 'fa fa-file-o', label: '0mag', tag: '综合', url: 'https://0mag.app/search?q=${keyword}' },
				// {icon: 'fa fa-file-o', label: '磁力宝', tag: '综合', url: 'http://clb3.in/s/${keyword}.html'},
				{ icon: 'fa fa-file-o', label: '高清族', tag: '影视', url: 'https://www.hdzu.cc/movie/filter?act=title&wd=${keyword}' },
				{ icon: 'fa fa-list', label: '无道杂货铺', tag: '聚合搜索平台', url: 'https://upanso.com/' },
				{ icon: 'fa fa-list', label: '资源猫', tag: '网站导航', url: 'https://www.ziyuanm.com/e/search/?searchget=1?&keyboard=${keyword}&show=title' },
				// {icon: 'fa fa-list', label: '万有导航', tag: '网站导航', url: 'http://wanyouw.com/'},
				{ icon: 'fa fa-list', label: '资源狗', tag: '网站导航', url: 'http://www.ziyuangou.com/' },
				{ icon: 'fa fa-list', label: '24k导航', tag: '网站导航', url: 'https://www.24kdh.net/' },
				{ icon: 'fa fa-list', label: '资源鸽导航', tag: '自媒体导航', url: 'https://www.resdove.com/' },
				{ icon: 'fa fa-list', label: '虫部落', tag: '聚合搜索平台', url: 'https://search.chongbuluo.com/' },
				// {icon: 'fa fa-list', label: '科塔学术', tag: '专业学术导航', url: 'https://site.sciping.com/'},
				{ icon: 'fa fa-list', label: '搜BaiDu盘', tag: '聚合搜索平台', url: 'https://www.sobaidupan.com/' },
				{ icon: 'fa fa-list', label: 'SOSO云盘', tag: '聚合搜索平台', url: 'https://www.sosoyunpan.com/' },
				{ icon: 'fa fa-link', label: '搜索源', tag: '聚合搜索平台', url: 'https://sousuoyuan.com/#s' },
				{ icon: 'fa fa-link', label: '电影狗', tag: '影视', url: 'https://www.dianyinggou.com/so/${keyword}' },
				{ icon: 'fa fa-link', label: '搜电影', tag: '影视', url: 'https://www.soudianying.net/search/?q=${keyword}' },
				// {icon: 'fa fa-link', label: '7080影视搜', tag: '影视', url: 'https://7080.wang/so.html?wd=${keyword}'},
				{ icon: 'fa fa-link', label: '电影天堂网', tag: '影视', url: 'http://s.ygdy8.com/plus/s01.php?typeid=1&keyword=${keyword}', encode: 'encodeGb2312' },
				// {icon: 'fa fa-link', label: '及搜盘', tag: '影视', url: 'http://www.jisoupan.com/search/${keyword}.html'},
				{ icon: 'fa fa-link', label: '小纸条', tag: '影视', url: 'https://u.gitcafe.net/' },
				{ icon: 'fa fa-link', label: '6v电影', tag: '影视', url: 'https://www.hao6v.cc/' },
				// {icon: 'fa fa-link', label: '种子吧', tag: 'BT|影视', url: 'http://seed18.com/search?wd=${keyword}'},
				// {icon: 'fa fa-link', label: 'SOBT', tag: 'BT|影视', url: 'http://sobt4.info/q/${keyword}.html'},
				// {icon: 'fa fa-link', label: 'btfox', tag: 'BT|影视', url: 'http://btfox9.info/s?wd=${keyword}'},
				{ icon: 'fa fa-link', label: 'Torrent Kitty', tag: 'BT|影视', url: 'https://cn.torrentkitty.red/search/${keyword}/' },
				{ icon: 'fa fa-link', label: '轻略搜索', tag: '综合', url: 'http://search.qinggl.com/s/?key=${keyword}&type=ziyuan&more=0&tid=5999&unique=b5333a8aacd4e183&target=0&scheme=http#' },
				{ icon: 'fa fa-link', label: '吾爱破解', tag: '站内搜索', url: 'http://zhannei.baidu.com/cse/site?q=${keyword}&cc=52pojie.cn&ie=gbk' },
				// 其他
				{ icon: 'fa fa-link', label: '小不点搜索', tag: '网站', url: 'https://www.xiaoso.net/m/search?wd=${keyword}' },
				// {icon: 'fa fa-link', label: 'Google镜像', tag: '网站', url: 'https://search.ahnu.cf/search?q=${keyword}'},
				// {icon: 'fa fa-link', label: 'Yandex', tag: '网站', url: 'https://yandex.com/search/?text=${keyword}'},
				{ icon: 'fa fa-link', label: '搜漫', tag: '漫画', url: 'https://www.soman.com/search.html?keyword=${keyword}' },
				{ icon: 'fa fa-link', label: '茶杯狐', tag: '影视', url: 'https://www.cupfox.app/search?key=${keyword}' },
				{ icon: 'fa fa-link', label: '问答库', tag: '试题', url: 'https://www.asklib.com/s/${keyword}' },
				{ icon: 'fa fa-link', label: '库问搜索', tag: '文献', url: 'http://www.koovin.com/?q=${keyword}' },
				// {icon: 'fa fa-link', label: '搜图导航', tag: '图片', url: 'https://www.91sotu.com/key/${keyword}'},
				// {icon: 'fa fa-link', label: 'Videvo', tag: '精品视频图片', url: 'https://www.videvo.net/search/${keyword}/'},
				{ icon: 'fa fa-link', label: '鸠摩搜书', tag: '书籍', url: 'https://www.jiumodiary.com/' },
				{ icon: 'fa fa-link', label: '熊猫搜书', tag: '文档', url: 'https://xmsoushu.com/' },
				{ icon: 'fa fa-link', label: '淘资源', tag: '资源论坛', url: 'https://www.panpanr.com/' },
				{ icon: 'fa fa-link', label: '云盘资源共享', tag: '综合', url: 'http://alipan.pan666.cn/' },
				{ icon: 'fa fa-link', label: 'rarbg', tag: '国外|影视|盗版', url: 'https://www.rarbg.to/' },
				{ icon: 'fa fa-link', label: 'iLovePDF', tag: 'PDF tools', url: 'https://www.ilovepdf.com/' },
				{ icon: 'fa fa-link', label: '爱资料工具', tag: '在线工具', url: 'https://www.toolnb.com/' },
				{ icon: 'fa fa-link', label: '个创之家', tag: '创业指导', url: 'https://www.torrent.org.cn/' },
				{ icon: 'fa fa-link', label: 'CTF资源库', tag: 'CTF', url: 'https://www.ctftools.com/' },
			],
			websiteActiveIndex: -1,
			keyword: '',
			iframeUrl: '',
			loadingCount: 0
		}
	},
	methods: {
		searchHandler() {
			let index = this.websiteActiveIndex > -1 ? this.websiteActiveIndex : 0
			this.websiteActiveIndex = -1
			this.itemClick(this.websiteList[index], index)
		},
		itemClick(item, index) {
			if (this.websiteActiveIndex === index) return
			this.websiteActiveIndex = index
			let keyword = this.keyword || ''
			if (item.encode) {
				let func = window[item.encode] || this.$jstools[item.encode]
				func && (keyword = func(keyword))
			}
			this.loadingCount++
			this.iframeUrl = ''
			this.$nextTick(() => {
				this.iframeUrl = item.url.replace('${keyword}', keyword)
			})
		},
		openByBrowser() {
			if (!this.iframeUrl) return
			shell.openExternal(this.iframeUrl)
		},
	},
}
</script>

<style scoped lang="less">
@import "~@/assets/css/_mixins.less";
@import "~@/assets/css/_color.less";

.page-search-helper {
	display: flex;
	flex-direction: column;

	fieldset {
		height: 100%;

		.fieldset-content {
			height: calc(100% - 2em);
			overflow: auto;
		}
	}

	.page-body {
		height: 0;
		flex-grow: 1;

		&>.row {
			height: 100%;
		}

		.left {
			height: 100%;

			.fieldset-content {
				display: flex;
				flex-direction: column;
			}

			.website-list {
				flex-grow: 1;
				padding: 0 1em;
				border-radius: .5em;
				color: #6c757d;
				background-color: @bgGrey;
				overflow: hidden auto;

				.website-item {
					padding: .5em 0;
					cursor: pointer;
					border-bottom: 1px dashed #bbb;

					&.active,
					&:hover {
						font-weight: 600;
						color: @colorWarning;
					}
				}
			}
		}

		.right {
			height: 100%;

			.fieldset-content {
				position: relative;
				border-radius: 0.5em;
			}

			iframe {
				display: block;
				width: 100%;
				height: 100%;
				border-radius: .5em;
				background-color: @bgGrey;
			}

			.iframe-btn {
				position: absolute;
				top: 5px;
				right: 5px;
				cursor: pointer;
			}
		}
	}
}</style>
